package sg.edu.nus.iss.team2s.jass.control;

/**
 * <p>The <strong>Job AdvertResponse Controller</strong> provides the functionality to controll 
 * the Job AdvertResponse.</p>
 * <p>There are three methods: <code>getJobSeeker(String loginId)</code>,<code>addJobAdvertResponse(JobAdvertResponse response)</code>
 * and <code>validateJobAdvertResponse(String key)</code>.
 * @author Zheng Xiaofeng
 * @version 1.0
 */

import sg.edu.nus.iss.team2s.jass.dao.DAOException;
import sg.edu.nus.iss.team2s.jass.dao.DAOFactory;
import sg.edu.nus.iss.team2s.jass.dao.DAOInterface;
import sg.edu.nus.iss.team2s.jass.dto.JobSeeker;
import sg.edu.nus.iss.team2s.jass.dto.JobAdvertResponse;

public class JobAdvertResponseController {
	/**
	 * Get the JobSeeker based on loginId
	 * @param loginId
	 * @return	JobSeeker object
	 * @throws Exception
	 */
	public static JobSeeker getJobSeeker(String loginId) throws Exception{
		DAOFactory factory = DAOFactory.getInstance();
		DAOInterface dao = factory.getDAO(JobSeeker.class.getName());
		JobSeeker jobSeeker = (JobSeeker)dao.get(loginId);
		return jobSeeker;
	}
	/**
	 * Create new JobAdvertResponse Record
	 * @param response	the specified JobAdvertResponse object
	 * @throws Exception
	 */
	public static void addJobAdvertResponse(JobAdvertResponse response) throws Exception {
		DAOFactory factory = DAOFactory.getInstance();
		DAOInterface dao = factory.getDAO(JobAdvertResponse.class.getName());
		dao.add(response);
	}
	/**
	 * Validate whether the specified JobAdvertResponse exists in property file
	 * @param key the search criteria of JobAdvertResponse.(Format: jobAdvertId + "|" + jobSeekerId)
	 * @return boolean
	 * @throws Exception
	 */
	public static boolean validateJobAdvertResponse(String key) throws Exception {
		DAOFactory factory = DAOFactory.getInstance();
		DAOInterface dao = factory.getDAO(JobAdvertResponse.class.getName());
		JobAdvertResponse response = null;
		try {
			response = (JobAdvertResponse)dao.get(key);
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
//			return false;
			throw new Exception("DAOException:" + e.getMessage());
		}
		if(response == null){
			return true;
		}
		else{
			return false;
		}
	}
}
